package com.gismore.demo.config;

import com.gismore.demo.config.interceptor.MvcExceptionInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Created by lei on 2017/5/31.
 */
@Component
public class InterceptorConfiguration extends WebMvcConfigurerAdapter {

	@Autowired
	private MvcExceptionInterceptor mvcExceptionInterceptor;

	public void addInterceptors(InterceptorRegistry registry){
		// 注册拦截器
		InterceptorRegistration ir = registry.addInterceptor(mvcExceptionInterceptor);
		// 配置拦截的路径
		ir.addPathPatterns("/**");
		// 配置不拦截的路径
		ir.excludePathPatterns("/**.html");

		// 还可以在这里注册其它的拦截器
		//registry.addInterceptor(new OtherInterceptor()).addPathPatterns("/**");
	}
}
